package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotations.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

//    @Insert("insert into employee (name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user)" +
//            "values" +
//            " (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})"
//    )
    Page<Category> pageQuery(CategoryPageQueryDTO queryDTO);

    @Insert("insert into category (type,sort, name, status, create_time, update_time, create_user, update_user) VALUES " +
            "(#{type},#{sort},#{name},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    void add(Category dto);

    @Delete("delete from category where id = #{id}")
    void delete(Long id);


    @AutoFill(OperationType.UPDATE)
    void startOrBin(Category category);


    List<Category> list(Integer type);

    /**
     * 根据套餐类的id获取套餐的名字
     * @param categoryId
     * @return
     */
    @Select("select category.name from category where id = #{categoryId}")
    String selectById(Long categoryId);

    @Select("select status from category where id = #{id}")
    Integer selectByIdForStatus(Long id);
}
